import numpy as np
import pandas as pd

s1 = pd.Series([0, 1], index=['a', 'b'])
s2 = pd.Series([2, 3, 4], index=['a', 'd', 'e'])
s3 = pd.Series([5, 6], index=['f', 'g'])
print(pd.concat([s1, s2, s3]))

print('================================================================')
from IPython.display import display

data1 = pd.DataFrame(np.arange(6).reshape(2, 3), columns=list('abc'))
data2 = pd.DataFrame(np.arange(20, 26).reshape(2, 3), columns=list('ayz'))
data = pd.concat([data1, data2], axis=0)
display(data1, data2, data)

print("--------------------------------------------------")


def MinMaxScale(data):
    data = (data - data.min()) / (data.max() - data.min())
    return data


x = np.array([[1., -1., 2.], [2., 0., 0., ], [0., 1., -1.]])
print('原始数据为:\n', x)
x_scaled = MinMaxScale(x)
print('标准化后矩阵为：\n', x_scaled, end='\n')

print('----------------------------------------------------------')
import pywt
import cv2 as cv
import matplotlib.pyplot as plt

img = cv.imread("1.png")
img = cv.resize(img, (448, 448))
# 将多通道图像转换为单通道图像
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY).astype(np.float32)
plt.figure(('二维小波一级变换'))
coeffs = pywt.dwt2(img, 'haar')
cA, (cH, cV, cD) = coeffs
# 将各子图进行拼接，最后得到一幅图
AH = np.concatenate([cA, cH + 255], axis=1)
VD = np.concatenate([cV + 255, cD + 255], axis=1)
img = np.concatenate([AH, VD], axis=0)
# 显示为灰度图
plt.axis('off')
plt.imshow(img, 'gray')
plt.title('result')
plt.show()
import numpy as np
import pandas as pd
from IPython.core.display_functions import display

# 创建Series对象
s1 = pd.Series([0, 1], index=['a', 'b'])
s2 = pd.Series([2, 3, 4], index=['a', 'd', 'e'])
s3 = pd.Series([5, 6], index=['f', 'g'])
# 合并s1乘以5和s3
s4 = pd.concat([s1 * 5, s3], sort=False)
# 按列合并s1和s4
s5 = pd.concat([s1, s4], axis=1, sort=False)
# 按列合并s1和s4，只有索引匹配的部分
s6 = pd.concat([s1, s4], axis=1, join='inner', sort=False)
# 显示结果
display(s5, s6)
print("--------------------------------")
display(s6.combine_first(s5))
print("--------------------------------")


def StandardScale(data):
    data = (data - data.mean()) / data.std()
    return data


x = np.array([[1., -1., 2.], [2., 0., 0.], [0., 1., -1.]])
print('原始数据为：\n', x)
x_scaled = StandardScale(x)
print('标准化后矩阵为\n', x_scaled, end='\n')
print("--------------------------------")
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn.datasets import load_iris

data = load_iris()
y = data.target
x = data.data
pca = PCA(n_components=2)
reduced_x = pca.fit_transform(x)
red_x, red_y = [], []
bule_x, bule_y = [], []
green_x, green_y = [], []
for i in range(len(reduced_x)):
    if y[i] == 0:
        red_x.append(reduced_x[i][0])
        red_y.append(reduced_x[i][1])
    elif y[i] == 1:
        bule_x.append(reduced_x[i][0])
        bule_y.append(reduced_x[i][1])
    else:
        green_x.append(reduced_x[i][0])
        green_y.append(reduced_x[i][1])
plt.scatter(red_x, red_y, c='r', marker='x')
plt.scatter(bule_x, bule_y, c='b', marker='D')
plt.scatter(green_x, green_y, c='g', marker='.')
plt.show()
